home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / goo / h / GString < prev    next >
Text File  |  1996-06-08  |  2KB  |  82 lines

  1. //========================================================================
  2. //
  3. // GString.h
  4. //
  5. // Simple variable-length string type.
  6. //
  7. // Copyright 1996 Derek B. Noonburg
  8. //
  9. //========================================================================
  10.  
  11. #ifndef GSTRING_H
  12. #define GSTRING_H
  13.  
  14. #ifdef __GNUC__
  15. //#pragma interface
  16. #endif
  17.  
  18. #include <string.h>
  19.  
  20. class GString {
  21. public:
  22.  
  23.   // Create an empty string.
  24.   GString();
  25.  
  26.   // Create a string from a C string.
  27.   GString(char *s1);
  28.  
  29.   // Create a string from <length1> chars at <s1>.  This string
  30.   // can contain null characters.
  31.   GString (char *s1, int length1);
  32.  
  33.   // Copy a string.
  34.   GString(GString *str);
  35.   GString *copy() { return new GString(this); }
  36.  
  37.   // Concatenate two strings.
  38.   GString(GString *str1, GString *str2);
  39.  
  40.   // Destructor.
  41.   ~GString();
  42.  
  43.   // Get length.
  44.   int getLength() { return length; }
  45.  
  46.   // Get C string.
  47.   char *getCString() { return s; }
  48.  
  49.   // Get <i>th character.
  50.   char getChar(int i) { return s[i]; }
  51.  
  52.   // Clear string to zero length.
  53.   GString *clear();
  54.  
  55.   // Append a character or string.
  56.   GString *append(char c);
  57.   GString *append(GString *str);
  58.   GString *append(char *str);
  59.  
  60.   // Insert a character or string.
  61.   GString *insert(int i, char c);
  62.   GString *insert(int i, GString *str);
  63.   GString *insert(int i, char *str);
  64.  
  65.   // Delete a character or range of characters.
  66.   GString *del(int i, int n = 1);
  67.  
  68.   // Compare two strings:  -1:<  0:=  +1:>
  69.   // These function assume the strings do not contain null characters.
  70.   int cmp(GString *str) { return strcmp(s, str->getCString()); }
  71.   int cmp(char *s1) { return strcmp(s, s1); }
  72.  
  73. private:
  74.  
  75.   int length;
  76.   char *s;
  77.  
  78.   void resize(int length1);
  79. };
  80.  
  81. #endif
  82.